package mornd.test1;

import lombok.ToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.StringJoiner;

/**
 * @author: mornd
 * @dateTime: 2023/5/4 - 19:49
 */
@ToString
public class Bean1 {
    private Bean2 bean2;
    private Bean3 bean3;

    @Autowired
    private Bean5 bean5;

    public Bean1() {
        System.out.println("Bean1 构造器");
    }

    @Autowired
    public void setBean2(Bean2 bean2) {
        System.out.println("@Autowired生效，" + bean2);
        this.bean2 = bean2;
    }

    @Resource
    public void setBean3(Bean3 bean3) {
        System.out.println("@Resource生效，" + bean3);
        this.bean3 = bean3;
    }

    private String name;

    @Autowired
    public void setName(@Value("${JAVA_HOME}") String name) {
        System.out.println("@Value生效，" + name);
        this.name = name;
    }

    @PostConstruct
    public void init() {
        System.out.println("初始化方法init()");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("销毁方法destroy()");
    }

}
